Linux_linux下通过iptables只允许指定ip地址访问指定端口的设置方法,首先,清除所有预设置复制代
首先,清除所有预设置
复制代码
代码如下:
iptables -F#清除预设表filter中的所有规则链的规则
iptables -X#清除预设表filter中使用者自定链中的规则 其次,设置只允许指定ip地址访问指定端口
其次,设置只允许指定ip地址访问指定端口
复制代码
代码如下:
iptables -A INPUT -s xxx.xxx.xxx.xxx -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -d xxx.xxx.xxx.xxx -p tcp --sport 22 -j ACCEPT
iptables -A INPUT -s xxx.xxx.xxx.xxx -p tcp --dport 3306 -j ACCEPT
iptables -A OUTPUT -d xxx.xxx.xxx.xxx -p tcp --sport 3306 -j ACCEPT
上面这两条,请注意--dport为目标端口,当数据从外部进入服务器为目标端口;反之,数据从服务器出去则为数据源端口,使用 --sport
同理,-s是指定源地址,-d是指定目标地址。
然后,关闭所有的端口
复制代码
代码如下:
iptables -P INPUT DROP
iptables -P OUTPUT DROP
iptables -P FORWARD DROP
最后,保存当前规则
复制代码
代码如下:
/etc/rc.d/init.d/iptables save
service iptables restart
这种iptables的规则设定适用于只充当MySQL服务器的管理和维护,外部地址不提供任何服务。
如果你希望yum可以运行的话,还需要添加以下内容,允许DNS请求的53端口,允许下载随机产生的高端口
复制代码
代码如下:
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -p udp --sport 53 -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 10000:65535 -j ACCEPT
/etc/rc.d/init.d/iptables save
service iptables restart
本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!
本文地址: https://v30.fanwenzhu.com/xt/linux/7354.shtml
相关文章
热门TAG
win10 ecshop 主机 阿里云 解决 配置 C# C++ 解析 SQL语句 命令 Go语言 方法 CSS3 HTML5 CSS win7 MSSQL 服务器配置 IIS7.5 IIS7 IIS6 IIS CentOS 7 Linux oracle数据库 oracle phpcms discuz discuz教程最新文章
-
并进行了数次优化更改
时间:2021-01-23
-
在Linus发表文章的第二年
时间:2021-01-23
-
当一个文件被加载时
时间:2021-01-21
-
与--delete 呼应的是--exis
时间:2021-01-21
-
$top top-18:50:38up6days
时间:2021-01-21
-
CLI和程序包管理器使开发
时间:2021-01-20
-
但是有时候这个系统上跑
时间:2021-01-20
-
配置好prometheus数据源
时间:2021-01-20
热门文章
-
Anki:让记忆更轻松的开源神器
时间:2020-12-22
-
配置好prometheus数据源
时间:2021-01-20
-
如何在Linux启动时自动启动LXD容器
时间:2020-12-22
-
使用Vi/Vim编辑器:基础篇
时间:2020-12-22
-
linux系统比windows系统声音小怎么办?
时间:2021-01-08
-
使用parallel利用起你的所有CPU资源
时间:2020-12-22
-
Zsync:一个仅下载文件新的部分的传输工
时间:2020-12-22
-
Linux SecureCRT显示乱码解决方案
时间:2021-01-05
-
linux 防御SYN攻击步骤详解
时间:2020-12-23
-
在Linus发表文章的第二年
时间:2021-01-23
